using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using InvasiveSpecies.Models;
using System.IO;

namespace InvasiveSpecies.Controllers
{
    public class GameController : Controller
    {
        //
        // GET: /Game/

        public ActionResult Index()
        {
            var dataContext = new DataClassesDataContext();
            var games = from g in dataContext.Games
                        select g;

            return View(games);
        }

        public ActionResult ShowGame(string id)
        {
            id = id.Replace('-', ' ');
            var dataContext = new DataClassesDataContext();

            try
            {
                Game game = dataContext.Games.First<Game>(g => g.Name == id);

                if (Request.IsAuthenticated)
                {
                    AccountProfile.CurrentUser.Reputation += game.Points;
                }

                return View(game);
            }
            catch
            {
                return RedirectToAction("Error");
            }
        }

        public ActionResult Error()
        {
            return View();
        }
    }
}
